< previous page page_122 next page >

Page 122
If you answered intVar1 is equal to 20 and intValue is equal to 30, youre wrong! The reason? The code has a bug. Theres a typo in the line that subtracts 50 from intVar1. Instead of intVar1 its typed as intVor1 (notice the o instead of a). If you forget to place Option Explicit at the top of the module that has this procedure, the code will run, but it will give you a bad result. If you run the code, it will give you 70 and 30, which are not the answers youre expecting.

Naming Variables
You must follow certain rules when naming your variables for use in your applications. First, the variable name must begin with a letter. After the beginning letter, the name may contain any combination of letters, numbers, and underscore characters. No punctuation or spaces are allowed in the name. The name can be up to 255 characters but may not be a reserved word. You may use the same name from one procedure to the next, but the variable names must be unique within the same scope. Avoid using one-letter variables because they are hard to understand when you come back to look at your program later. Be careful that you do not use any Visual Basic keywords. These are words that are used in the Visual Basic language and cannot be used as variable names. For a complete list of keywords, look in the Visual Basic Books Online under the Visual Basic Help topic.
Variable Naming Standards
A standard has emerged for naming variables in Visual Basic. It is a variation of the Hungarian Notation used in C language programming. Table 6.4 contains a list of data types and the suggested prefixes you should use when naming your variables. A complete reference may be found in Appendix A of this book.
In this book, youll see a consistent standard of variable names. You should strive to follow these standards closely in your programming because it will make your programs much easier to read. Heres a condensed list of some general rules to follow when naming variables:
Make all variable names mixed casein other words, each word or abbreviation should be capitalized.
Preface each variable name with the type of data it contains.

 
< previous page page_122 next page >

If you like this book, buy it!